// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderStatusProcessor.java

package com.boci.clientapp.orderstatus.processor;

import com.boci.clientapp.orderstatus.vo.OrderStatusDetailVO;
import com.boci.clientapp.orderstatus.vo.OrderStatusVO;
import com.boci.common.processor.AbstractResponseProcessor;
import com.boci.common.vo.ResponseVO;
import java.util.ArrayList;
import org.w3c.dom.*;

public class OrderStatusProcessor extends AbstractResponseProcessor
{

    public OrderStatusProcessor(String pXML, String pReqType)
        throws Exception
    {
        super(pXML, pReqType, "ORDER_STATUS.ERROR_");
        allVOList = new ArrayList();
        hkStockList = new ArrayList();
        usStockList = new ArrayList();
        hkOptionList = new ArrayList();
        usOptionList = new ArrayList();
    }

    public ResponseVO processXML()
        throws Exception
    {
        OrderStatusVO orderStatusVO = new OrderStatusVO(getReqType(), getReturnCode());
        NodeList orderStatusDetailList = resultDocument.getElementsByTagName("ORDER");
        transformVOList(orderStatusDetailList);
        orderStatusVO.setOrderStatusDetailVOList(allVOList);
        orderStatusVO.setHkStockList(hkStockList);
        orderStatusVO.setUsStockList(usStockList);
        orderStatusVO.setHkOptionList(hkOptionList);
        orderStatusVO.setUsOptionList(usOptionList);
        return orderStatusVO;
    }

    public void transformVOList(NodeList pNodeList)
    {
        int nodeLength = pNodeList.getLength();
        for(int i = 0; i < nodeLength; i++)
        {
            OrderStatusDetailVO orderStatusDetailVO = new OrderStatusDetailVO(getReqType(), getReturnCode());
            Element element = (Element)pNodeList.item(i);
            String strMarketId = getNodeValue(element, "MARKET_ID");
            String strProductLine = getNodeValue(element, "PRODUCT_LINE");
            String strSymbol = getNodeValue(element, "SYMBOL");
            String strName = getNodeValue(element, "NAME");
            String strName_CHI = getNodeValue(element, "NAME_CHI");
            String strName_CHS = getNodeValue(element, "NAME_CHS");
            String strOrderDuration = getNodeValue(element, "ORDER_DURATION");
            String strOriginalQuantity = getNodeValue(element, "ORIGINAL_QUANTITY");
            String strFilledQuantity = getNodeValue(element, "FILLED_QUANTITY");
            String strOutstandingQuantity = getNodeValue(element, "OUTSTANDING_QUANTITY");
            String strReducedQuantity = getNodeValue(element, "REDUCED_QUANTITY");
            String strCanceledQuantity = getNodeValue(element, "CANCELED_QUANTITY");
            String strBuyOrSell = getNodeValue(element, "BUY_OR_SELL");
            String strPrice = getNodeValue(element, "PRICE");
            String strCurrency = getNodeValue(element, "CURRENCY");
            String strOrderType = getNodeValue(element, "ORDER_TYPE");
            String strOrderQualifier = getNodeValue(element, "ORDER_QUALIFIER");
            String strOrderStatus = getNodeValue(element, "ORDER_STATUS");
            String strPlacementDate = getNodeValue(element, "PLACEMENT_DATE");
            String strOrderQuantity = getNodeValue(element, "ORDER_QUANTITY");
            String strAllowCancel = getAttrValue(element, "ALLOW_CANCEL");
            boolean allowCancelFlag;
            if(strAllowCancel != null && "TRUE".equals(strAllowCancel))
                allowCancelFlag = true;
            else
                allowCancelFlag = false;
            String strAllowChange = getAttrValue(element, "ALLOW_CHANGE");
            boolean allowChangeFlag;
            if(strAllowChange != null && "TRUE".equals(strAllowChange))
                allowChangeFlag = true;
            else
                allowChangeFlag = false;
            String strOrderId = getAttrValue(element, "ORDER_ID");
            orderStatusDetailVO.setMarketId(strMarketId);
            orderStatusDetailVO.setProductLine(strProductLine);
            orderStatusDetailVO.setSymbol(strSymbol);
            orderStatusDetailVO.setName(strName);
            orderStatusDetailVO.setName_chi(strName_CHI);
            orderStatusDetailVO.setName_chs(strName_CHS);
            orderStatusDetailVO.setOrderDuration(strOrderDuration);
            orderStatusDetailVO.setOriginalQuantity(strOriginalQuantity);
            orderStatusDetailVO.setFilledQuantity(strFilledQuantity);
            orderStatusDetailVO.setOutstandingQuantity(strOutstandingQuantity);
            orderStatusDetailVO.setReducedQuantity(strReducedQuantity);
            orderStatusDetailVO.setCanceledQuantity(strCanceledQuantity);
            orderStatusDetailVO.setBuyOrSell(strBuyOrSell);
            orderStatusDetailVO.setPrice(strPrice);
            orderStatusDetailVO.setCurrency(strCurrency);
            orderStatusDetailVO.setOrderType(strOrderType);
            orderStatusDetailVO.setOrderQualifier(strOrderQualifier);
            orderStatusDetailVO.setOrderStatus(strOrderStatus);
            orderStatusDetailVO.setPlacementDate(strPlacementDate);
            orderStatusDetailVO.setAllowCancel(allowCancelFlag);
            orderStatusDetailVO.setAllowChange(allowChangeFlag);
            orderStatusDetailVO.setOrderId(strOrderId);
            orderStatusDetailVO.setOrderQuantity(strOrderQuantity);
            allVOList.add(orderStatusDetailVO);
            String strUpperMarketId = strMarketId.toUpperCase();
            if(strUpperMarketId.equals("HK"))
            {
                hkStockList.add(orderStatusDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("US"))
            {
                usStockList.add(orderStatusDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("OPTION"))
            {
                hkOptionList.add(orderStatusDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("USOPTION"))
                usOptionList.add(orderStatusDetailVO);
        }

    }

    ArrayList allVOList;
    ArrayList hkStockList;
    ArrayList usStockList;
    ArrayList hkOptionList;
    ArrayList usOptionList;
}
